/*条件选择弹窗*/
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_pickers/pickers.dart';
import 'package:flutter_pickers/time_picker/model/date_mode.dart';
import 'package:flutter_pickers/style/picker_style.dart';
import 'package:flutter_pickers/time_picker/model/pduration.dart';
import 'package:frametrim/listeners/OnDialogClickListener.dart';
import 'package:frametrim/utility/sq_color.dart';
import 'package:frametrim/utility/timeUtil.dart';

/**https://github.com/longer96/flutter_pickers
 *  ('年月日时分秒', DateMode.YMDHMS),
 *  ('年月日时分', DateMode.YMDHM),
 * ('年月日时', DateMode.YMDH),
 * ('年月日', DateMode.YMD),
 * ('年月', DateMode.YM),
 * ('年', DateMode.Y),
 * ('月日时分秒', DateMode.MDHMS),
 *('时分秒', DateMode.HMS),
 * ('月日', DateMode.MD),
 *('月', DateMode.S),
 *('仿计时器', DateMode.HMS),
 **/
class PickerDialogs {
  static Widget _cancelButton = Container(
    height: 40,
    padding: const EdgeInsets.symmetric(horizontal: 15),
    child: Center(
      child: Text(
        '取消',
        style: TextStyle(color: Color(0xff666666), fontSize: 16),
      ),
    ),
  );

  static Widget _commitButton = Container(
    height: 40,
    padding: const EdgeInsets.symmetric(horizontal: 15),
    decoration: BoxDecoration(
        color: SQColor.white, borderRadius: BorderRadius.circular(4)),
    child: Center(
      child: Text(
        '确认',
        style: TextStyle(color: SQColor.primary, fontSize: 16),
      ),
    ),
  );

  // 头部样式
  static Decoration headDecoration = BoxDecoration(
      color: Colors.white,
      borderRadius: BorderRadius.only(
          topLeft: Radius.circular(0), topRight: Radius.circular(0)));

  /// item 覆盖样式
  static Widget itemOverlay = Container(
    decoration: BoxDecoration(
      border: Border.symmetric(
          horizontal:
              BorderSide(color: Colors.cyan.withOpacity(0.3), width: 0.7)),
    ),
  );

  static var pickerStyle = PickerStyle(
    backgroundColor: Colors.white,
    cancelButton: _cancelButton,
    commitButton: _commitButton,
    headDecoration: headDecoration,
    title: Center(
      child: Text(
        '选择时间',
        style: TextStyle(fontSize: 16, color: SQColor.color_222222),
      ),
    ),
    textColor: Colors.black,
    itemOverlay: itemOverlay,
  );

  /**
   * 年份选择器
   */
  static void showYearPicker(
      BuildContext context, String title, Function(PDuration) onSure) {
    Pickers.showDatePicker(
      context,
      // 模式，详见下方
      mode: DateMode.Y,
      // 样式  详见下方样式
      pickerStyle: pickerStyle,
      // 默认选中
      selectDate: PDuration(year: TimeUtil.getYear()),
      minDate: PDuration(year: 2021),
      maxDate: PDuration(year: TimeUtil.getYear() + 10),
      onConfirm: (p) {
        onSure(p);
        print('longer >>> 返回数据：$p');
      },
      // onChanged: (p) => print(p),
    );
  }

  /**
   * 年+月选择器
   */
  static void showYearMonthPicker(
      BuildContext context, String title, Function(PDuration) onSure) {
    Pickers.showDatePicker(
      context,
      // 模式，详见下方
      mode: DateMode.YM,
      // 样式  详见下方样式
      pickerStyle: pickerStyle,
      // 默认选中
      selectDate:
          PDuration(year: TimeUtil.getYear(), month: TimeUtil.getMonth()),
      minDate: PDuration(year: 2021, month: 1),
      maxDate: PDuration(year: TimeUtil.getYear() + 10, month: 12),
      onConfirm: (p) {
        onSure(p);
        print('longer >>> 返回数据：$p');
      },
    );
  }
}
